package com.yujistu.network;

import android.content.Context;

import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;

/**
 * Created by S3YOGA on 2015/11/3.
 */
public class StuRestClient {

    /**
     *
     上线正式服务器: http://api.binduyoga.cn/v1.0/
     测试服务器: http://testapi.binduyoga.cn/v1.0/
     */
    private static final String BASE_URL = "http://doc.yogiplus.cn/v1.0/";

    private String LoginURL= "/account/login";

    private static AsyncHttpClient  client = new AsyncHttpClient();

    public static AsyncHttpClient getClient() {
        return client;
    }

    public static void close(Context context){
        client.cancelRequests(context, true);
    }

    public static String getAbsoluteUrl(String relativeUrl){
        return BASE_URL + relativeUrl;
    }

    public static void get(Context context, String url, RequestParams params, AsyncHttpResponseHandler responseHandler) {
         client.setTimeout(30000);
         client.get(context, getAbsoluteUrl(url), params, responseHandler);
    }

    public static void post(Context context, String url, RequestParams params, AsyncHttpResponseHandler responseHandler) {
        client.setTimeout(30000);
        client.post(context, getAbsoluteUrl(url), params, responseHandler);
    }

    public static void get(String url, RequestParams params, AsyncHttpResponseHandler handler) {
        client.get(url, params, handler);
    }

    public static void setHttpClient(AsyncHttpClient c) {
        client = c;
    }
}
